package com.gitee.cashzhang27.test.boot.reactive.webflux.router;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

import com.gitee.cashzhang27.test.boot.reactive.webflux.handler.TimeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/03/27 11:29
 */
@Configuration
public class TimeRouter {

  @Autowired
  private TimeHandler timeHandler;

  @Bean
  public RouterFunction<ServerResponse> timerRouter() {
    return route(GET("/time"), timeHandler::getTime)
        .andRoute(GET("/date"), timeHandler::getDate)
        .andRoute(GET("/times"), timeHandler::sendTimePerSec);
  }
}
